//
//  EAGLView.h
//  MathMastersAsteroids
//
//  Created by Jordon Phillips on 3/1/10.
//  Copyright __MyCompanyName__ 2010. All rights reserved.
//
//  This is the main game class, it is based on the EAGLView class from the openGL template in the iPhone sdk

#import <UIKit/UIKit.h>
#import <QuartzCore/QuartzCore.h>
#import <stdlib.h>
#import "ESRenderer.h"

#import "Player.h"
#import "Asteroid.h"
#import "Equation.h"
#import "SoundController.h"

// This class wraps the CAEAGLLayer from CoreAnimation into a convenient UIView subclass.
// The view content is basically an EAGL surface you render your OpenGL scene into.
// Note that setting the view non-opaque will only work if the EAGL surface has an alpha channel.
@interface EAGLView : UIView
{    
@private
	id <ESRenderer> renderer;//the renderer
	
	BOOL animating;//is true if the game is animating
	BOOL displayLinkSupported;
	NSInteger animationFrameInterval;//how long each frame takes
	// Use of the CADisplayLink class is the preferred method for controlling your animation timing.
	// CADisplayLink will link to the main display and fire every vsync when added to a given run-loop.
	// The NSTimer class is used only as fallback when running on a pre 3.1 device where CADisplayLink
	// isn't available.
	id displayLink;
    NSTimer *animationTimer;//the timer for using animation
	CGPoint touchPoint;//the point the user touches
	BOOL touchActive;//returns true if the screen is being touched
	int bulletCount;//counts the number of bullets on screen
	NSTimer *asteroid1Timer;//timer for asteroid 1's generation
	NSTimer *asteroid2Timer;//timer for asteroid 2's generation
	NSTimer *asteroid3Timer;//timer for asteroid 3's generation
	NSTimer *equationTimer;//increments the equation timer
	NSTimer *difficultyTimer;//timer for when a difficulty increase occurs
	NSTimer *messageTimer;//timeout for on screen messages
	int equationTime;//the current time left for the current equation
	float equationTimeMax;//the max time for the equation timer
	UILabel *scoreDisplay;//the label to display the score
	UILabel *equationDisplay;//the label to display the current equation
	int score;//the actual score value
	Sprite *healthBar;//the health bar image
	Sprite *timeBar;//the time bar image
	Sprite *starField;//the starfield image
	Equation *equation;//the current equation
	Sprite *correct;//the correct image for when an equation is completed successfully
	Sprite *wrong;//the wrong image for when an equation is completed wrong
	BOOL pause;//is true if the game is to be paused
	
	Player *player;//the player the user controls
	Asteroid* asteroids[3];//the array of asteroids
	SoundController *sound;//plays sounds
	
	int difficulty;//the game difficulty 0=easy 1=medium 2=hard
	BOOL soundToggle;//determines if sound is on or off
	BOOL musicToggle;//determines if music is on or off
	
}

@property (readonly, nonatomic, getter=isAnimating) BOOL animating;
@property (nonatomic) NSInteger animationFrameInterval;
@property int bulletCount;
@property UILabel *scoreDisplay;
@property UILabel *equationDisplay;
@property int score;
@property Sprite *healthBar;
@property Sprite *timeBar;
@property int equationTime;
@property float equationTimeMax;
@property Equation *equation;
@property Sprite *correct;
@property Sprite *wrong;
@property Player *player;
@property BOOL pause;
@property int difficulty;
@property BOOL soundToggle;
@property BOOL musicToggle;

- (void) startAnimation;
- (void) stopAnimation;
- (void) drawView:(id)sender;
- (void) initGame;
- (void) gameLoop;
- (void) drawBullets;
- (void) collisionDetection;
- (void) generateAsteroid1;
- (void) generateAsteroid2;
- (void) generateAsteroid3;
- (void) updateGui;
- (void) equationCountDown;
- (void) adjustDifficulty;
- (void) clearMessage;
- (void) resetTouchPoint;
- (void) soundOn;
- (void) soundOff;
- (void) setDifficulty:(int)newDiff;

@end
